Socket
Socket
Sign inDemoInstall

@toolz/session-storage-is-available

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@toolz/session-storage-is-available

A simple utility function to safely determine whether sessionStorage is available in the current environment


Version published
Weekly downloads
488
decreased by-7.22%
Maintainers
1
Weekly downloads
 
Created
Source

session-storage-is-available

session-storage-is-available is a tiny utility function to safely determine whether sessionStorage is available in the current environment. It's dangerous to assume that sessionStorage() is available. It can be absent in non-supported browsers, or when scripts are invoked from the command line, or when the user's browser is in Incognito Mode. Trying to access sessionStorage() when it's unavailable can spawn an Error. So it's best to test for its existence before attempting to access it.

Usage

After installation, import the package:

import { sessionStorageIsAvailable } from '@toolz/session-storage-is-available';

sessionStorageIsAvailable()

sessionStorageIsAvailable() attempts to set-and-remove a value in sessionStorage, returning a Boolean value based on its failure or success.

const API = {
   arguments: {
      // none
   },
   returns: Boolean,
}

Examples:

sessionStorageIsAvailable(); // returns Boolean TRUE in "normal" browser situations
sessionStorageIsAvailable(); // returns Boolean FALSE when invoked outside a "normal" browser
                             // or when the browser can sessionStorage disabled (e.g., Incognito Mode)

Keywords

FAQs

Package last updated on 19 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc